package com.devin.dao;

import com.devin.pojo.Product;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.cache.decorators.LruCache;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

@Mapper
@CacheNamespace(blocking = true,eviction = LruCache.class,flushInterval = 0L,size=1024,readWrite = true)
public interface ProductMapper {
    @Select("select * from product")
    @Results({@Result(id = true,property = "id",column = "id")
            ,@Result(property = "departureTime"
            ,column = "DepartureTime"
            ,jdbcType = JdbcType.DATE)
    })
    @Options(useCache=true)
    List<Product> getProducts();

    @Select(" select * from product where id =#{id}")
    @Options(useCache=true)
    Product getProductById(Integer id);

    @Insert("insert into product values(null,replace(UUID(),'-',''),#{productName},#{cityName},#{departureTime},#{productPrice},#{productDesc},#{productStatus})")
    void addProduct(Product product);

    @Update(" update product set productName=#{productName},cityName=#{cityName},DepartureTime=#{departureTime},productPrice=#{productPrice},productDesc=#{productDesc},productStatus=#{productStatus} where id=#{id}")
    void updateProduct(Product product);

    @Delete(" delete from product where id=#{productId}")
    void delProduct(Integer productId);
}
